class Solution:
    def findDuplicate(self, nums):
        slow = nums[0]
        fast = nums[nums[0]]
        
        # 寻找相遇点
        while slow != fast:
            slow = nums[slow]
            fast = nums[nums[fast]]
        
        # 寻找环的入口
        slow = 0
        while slow != fast:
            slow = nums[slow]
            fast = nums[fast]
        
        return slow